package com.yexiao.cofe.util;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author lkl
 * @since 2025/4/8
 */
@Component
@Data
public class FileUtil {
    private final Path fileStorageLocation;

    public FileUtil(@Value("${file.upload-dir}") String uploadDir) {
        this.fileStorageLocation = Paths.get(uploadDir).toAbsolutePath().normalize();
        try {
            Files.createDirectories(this.fileStorageLocation); // 创建目录
        } catch (Exception ex) {
            throw new RuntimeException("无法创建上传目录！", ex);
        }
    }
}
